Repository navigation
refactor(pptx): move font embedding out of PptxRenderEnvironment - #1082
Merged
Merged
Conversation
PptxRenderEnvironment had grown to 1,426 lines, most of them the embedding of registered and bundled font families. The embedding now lives in package-private classes beside it: - PptxDeckFonts: which registered families the deck carries, the viewer family a run is written with, the faces the runs drew, the bundled pass after the last slide, and the render.pptx.font.substitution lines; - PptxFontEmbedder: reading a family's faces, refusing it whole, claiming its style slots and handing the programs to the presentation, with the embed.skipped, shared.family and name.mismatch lines; - PptxSlotLedger: which face holds each style slot of a declared viewer family, with the Seated record; - PptxFontFace: a family's four faces, shared by the two above. The environment keeps every public method; the font ones delegate. The moved code is the original lines; what differs is visibility, the names the move changes and the javadoc references that now cross a class. No behaviour change: decks rendered with deterministic(...) are the same bytes, and the render log carries the same lines in the same order.
…says The CHANGELOG entry counted three classes beside PptxRenderEnvironment where the split made four, PptxFontFace included, and said the shared.family and name.mismatch lines name why a face did not travel; only embed.skipped does. Two long lines rewrapped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PptxRenderEnvironmentis the per-render state every PPTX handler draws through: slide surfaces, transform groups, pictures and navigation records. Font embedding grew inside it until it was most of the file: 1,426 lines ondevelop, against the project's 500. Embedding is a responsibility of its own:What changed
Four package-private types in
com.demcha.compose.document.backend.fixed.pptxtake the font code:PptxDeckFonts(433 lines) — the fonts of one render:fontFamily(...)with itsrender.pptx.font.substitutionlines;tokensTheNameMaySpeakand the viewer metrics by family;embedsBundledFonts(boolean)andembedBundledFontsUsed();warn…methods.PptxFontEmbedder(487 lines, static) —embedFontFamilyWithMetrics,embedFontFamily,readPrograms,claimSlotsAndReportSharing,handOverProgramsand theFamilyProgramsrecord. With them go theembed.skipped,shared.familyandname.mismatchlines they write.PptxSlotLedger(133 lines) — the formerPptxRenderEnvironment.SlotLedger. TheSeatedrecord, a sibling of it in the environment, now sits inside it.PptxFontFace(29 lines) — the four faces of a family, the formerPptxRenderEnvironment.Face, shared by the two classes above.PptxRenderEnvironment(471 lines) holds aPptxDeckFontsand delegates to it.fontFamily(...),runIsBold/runIsItalic,viewerAscentand the two package-private bundled-font methods keep their signatures, so no handler or caller changes. Public API is unchanged and the knowledge pack is untouched.The moved code is the original lines, sliced from the file rather than retyped. Every non-blank line of the original is accounted for in the new files. What differs:
private→ package-private where another class now calls a member;SlotLedger→PptxSlotLedger,Face→PptxFontFace, calls qualified withPptxFontEmbedder.;What is new is the wiring:
PptxDeckFonts' constructor and itsviewerMetrics(FontName)accessor;PptxFontEmbedder's private constructor;Documentation:
CHANGELOG.md(2.5.2, Internal);docs/architecture/backend-capability-details.mdand the javadoc ofDocxFontTable,PptxFontMappingandPptxEmbeddedFontnow name the classes the code lives in.Verification
I compared deck bytes and the render log before (
developateb80150ef) and after, using a throwaway probe test that is not committed:20 decks rendered with
deterministic(...)are identical by SHA-256. They cover:-Boldregistration, and a registration under a bundled family's viewer name;AsapCondensed's name mismatch;Each was rendered with bundled embedding on and off where that matters.
259 render-log lines, captured at DEBUG while those decks rendered, are the same text in the same order (timings masked).
The 6 demo decks written by the module's parity tests: all 245 parts are identical by SHA-256.
docProps/core.xml, which carries the time, is excluded.The probe has no deck where two faces of one definition read back as one slot, and none with a face whose licence forbids embedding. Those paths are covered by the unit tests and the sabotage below.
Sabotage: 8 of 8 caught. Each sabotage breaks one moved responsibility and is run against its own single test (
Tests run: 1, Failures: 1every time). Sources are restored and SHA-checked afterwards. The eight are: the run path's ledger question inPptxDeckFonts.fontFamily; reporting a registered family once per name; the cross-family slot refusal inreadPrograms; the ledger's case-insensitive match;runIsBold's delegation;viewerAscent's viewer metrics; the bundled pass's delegation; and the shared-name warning.Module runs on the final tree:
./mvnw -B -ntp test -pl :graph-compose-render-pptx -am— 205 run, 0 failed — the same 205 as ondevelop../mvnw -B -ntp test -f qa/pom.xml, after installing — 1926 run, 0 failed, 1 skipped.The full local gate runs before this leaves draft.